package com.vf.admin.client.controller.pay.wechatpay;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.vf.admin.client.common.ClientBaseController;
import com.vf.admin.client.common.ClientConstants;
import com.vf.admin.client.controller.pay.sandpay.SandpayService;
import com.vf.admin.client.controller.pay.sandpay.alipay.SandAliPayService;
import com.vf.admin.client.controller.pay.sandpay.weixin.SandWeiXinPayService;
import com.vf.admin.client.dao.VipOrderDao;
import com.vf.admin.client.result.PayInfoResult;
import com.vf.admin.client.service.*;
import com.vf.admin.common.Constants;
import com.vf.admin.common.entity.Result;
import com.vf.admin.fiwork.controller.AppDailyTasController;
import com.vf.admin.miaodong.entity.*;
import com.vf.admin.miaodong.service.AfterAppTicketPackageService;
import com.vf.admin.miaodong.service.AfterUserService;
import com.vf.admin.utils.Md5Util1;
import com.vf.admin.utils.UaUtil;
import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner;
import com.wechat.pay.contrib.apache.httpclient.auth.Verifier;
import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials;
import com.wechat.pay.contrib.apache.httpclient.cert.CertificatesManager;
import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
import org.apache.hadoop.mapred.IFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

import static com.vf.admin.common.Constants.*;

/**
 * <p>Title : </p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows10</p>
 *
 * @Author : NemoMeng
 * @Date 2023/6/25 11:29
 */
@Controller
@CrossOrigin
@RequestMapping(value = "/api/wechatVersion3")
public class ApiWeChatVersion3Controller extends ClientBaseController {


    private Logger logger = LoggerFactory.getLogger(getClass());


    @Autowired
    private SandWeiXinPayService sandWeiXinPayService;

    //微信支付配置业务
    @Autowired
    private WechatPayConfigsService wechatPayConfigsService;

    //appSetup设置
    @Autowired
    private AppSetupService appSetupService;
    //用户信息
    @Autowired
    private AppUserService appUserService;
    //充值金额信息
    @Autowired
    private AppCzMoneyService appCzMoneyService;
    //钱包订单
    @Autowired
    private AppOrderService appOrderService;
    //
    @Autowired
    private VipOrderDao vipOrderDao;

    @Autowired
    AfterUserService afterUserService;


    @Autowired
    private AppMingXiZuanShiService appMingXiZuanShiService;
    @Autowired
    private AppMingxiChongzhiService appMingxiChongzhiService;
    @Autowired
    private AppDailyTasController appDailyTasController;
    @Autowired
    private AppInvitationRecordService appInvitationRecordService;
    @Autowired
    private AgentUserService agentUserService;
    @Autowired
    private AppPrivilegeService appPrivilegeService;


    //会员充值金额信息
    @Autowired
    private VipPackageService vipPackageService;
    //vip订单
    @Autowired
    private VipOrderService vipOrderService;

    @Autowired
    private SandpayService sandpayService;
    @Autowired
    private PhpUserService phpUserService;

    @Resource
    private AfterAppTicketPackageService afterAppTicketPackageService;

    /**
     * 商城支付
     */
    @RequestMapping(value = "/shopH5", method = RequestMethod.POST)
    @ResponseBody
    public Result shopH5(String name, BigDecimal price) {
        PayInfoResult payInfoResult = wechatPayConfigsService.shopH5(request, name, price);
        return this.sucessJSON(payInfoResult);
    }

    @RequestMapping(value = "/rechargeJsApi")
    @ResponseBody
    public Result diamondRechargeWeChatWeb(HttpServletRequest request, Integer type, Integer projectId, String mobileSpec, String openid) {

        if (ObjectUtil.isEmpty(mobileSpec)) {
            String os = UaUtil.getOs(request);
            if (ObjectUtil.isNotEmpty(os)) {
                mobileSpec = os;
            }

        }
        if (type == 1) {
            try {
                //提示
                AppSetup setup = appSetupService.get();
                if (setup.getOpenRecharge() == 0) {
                    return this.errorJSON(setup.getRechargeTip());
                }
                //获取用户信息
                AppUser user = appUserService.get(getUserId());
                AppCzMoney appCzMoney = appCzMoneyService.get(projectId);
                Map<String, String> map = wechatPayConfigsService.jsApiDiamondRecharge(request, user, appCzMoney, mobileSpec, openid);
                if (ObjectUtil.isEmpty(map)) {
                    return this.errorJSON("充值失败，请您重新充值!");
                }
                return this.sucessJSON(map);
            } catch (Exception e) {
                logger.error("微信充值异常:", e);
                return this.errorJSON("服务器繁忙，请您稍后重试!");
            }
        }
        return null;

    }


    /**
     * h5 下单接口
     *
     * @param request
     * @param type      1钻石  2会员
     * @param projectId 根据type选择 项目id
     * @return
     */
    @RequestMapping(value = "/rechargeH5")
    @ResponseBody
    public Result diamondRechargeWeChatWeb(HttpServletRequest request, Integer type, Integer projectId, String mobileSpec, Integer userId, BigDecimal price) {

        if (ObjectUtil.isEmpty(mobileSpec)) {
            String os = UaUtil.getOs(request);
            if (ObjectUtil.isNotEmpty(os)) {
                mobileSpec = os;
            }

        }


        PaySelect paySelect = sandpayService.getPaySelect();


        if (paySelect.getType().equals(1)) {
            if (type == 1) {
                //提示
                AppSetup setup = appSetupService.get();
                if (setup.getOpenRecharge() == 0) {
                    return this.errorJSON(setup.getRechargeTip());
                }
                //获取用户信息
                AppUser user = appUserService.get(getUserId());
                AppCzMoney appCzMoney = appCzMoneyService.get(projectId);
                //杉德支付业务
                PayInfoResult payInfoResult = sandWeiXinPayService.diamondRechargeH5(request, user, appCzMoney, mobileSpec);

                return this.sucessJSON(payInfoResult);
            }
            if (type == 2) {
                //提示
                AppSetup setup = appSetupService.get();
                if (setup.getOpenBuyVip() == 0) {
                    return this.errorJSON(setup.getBuyVipTip());
                }
                //获取用户信息
                AppUser user = appUserService.get(getUserId());
                VipPackage vipPackage = vipPackageService.info(projectId);
                //杉德支付业务
                PayInfoResult payInfoResult = sandWeiXinPayService.openVipRechargeH5(request, user, vipPackage, mobileSpec);

                return this.sucessJSON(payInfoResult);

            }

            if (type == 3) {
                try {

                    //获取用户信息
                    AppUser user = appUserService.get(getUserId());
                    VipPackage vipPackage = new VipPackage();
                    vipPackage.setId(1000);
                    AppTicketPackage appTicketPackage = afterAppTicketPackageService.getList().get(0);
                    BigDecimal money = appTicketPackage.getMoney();
                    vipPackage.setPrice(money);
//                    vipPackage.setPrice(new BigDecimal("28.00"));
//                    vipPackage.setPrice(new BigDecimal("0.01"));
                    PayInfoResult payInfoResult = sandWeiXinPayService.openVipRechargeH5(request, user, vipPackage, mobileSpec);
                    if (ObjectUtil.isEmpty(payInfoResult)) {
                        return this.errorJSON("充值失败，请您重新充值!");
                    }
                    return this.sucessJSON(payInfoResult);
                } catch (Exception e) {
                    logger.error("支付宝充值异常:", e);
                    return this.errorJSON("服务器繁忙，请您稍后重试!");
                }
            }

            //php门票
            if (type == 4) {
                try {
                    //组装用户信息
                    AppUser user = new AppUser();
                    user.setId(userId);//用户id
                    user.setNick("之约");
                    user.setLoginname(userId.toString());
                    //组装门票价格
                    VipPackage vipPackage = new VipPackage();
                    vipPackage.setId(projectId);
                    vipPackage.setPrice(price);

                    PayInfoResult payInfoResult = sandWeiXinPayService.openVipRechargeH5(request, user, vipPackage, mobileSpec);

                    if (ObjectUtil.isEmpty(payInfoResult)) {
                        return this.errorJSON("充值失败，请您重新充值!");
                    }
                    return this.sucessJSON(payInfoResult);
                } catch (Exception e) {
                    logger.error("支付宝充值异常:", e);
                    return this.errorJSON("服务器繁忙，请您稍后重试!");
                }

            }
            if (type == 5) {

                try {
                    //组装用户信息
                    AppUser user = new AppUser();
                    user.setId(userId);//用户id
                    user.setNick("之约");
                    user.setLoginname(userId.toString());

                    //组装vip价格
                    VipPackage vipPackage = new VipPackage();
                    vipPackage.setId(projectId);  //
                    vipPackage.setPrice(price);

                    PayInfoResult payInfoResult = sandWeiXinPayService.openVipRechargeH5(request, user, vipPackage, mobileSpec);

                    if (ObjectUtil.isEmpty(payInfoResult)) {
                        return this.errorJSON("充值失败，请您重新充值!");
                    }
                    return this.sucessJSON(payInfoResult);
                } catch (Exception e) {
                    logger.error("支付宝充值异常:", e);
                    return this.errorJSON("服务器繁忙，请您稍后重试!");
                }

            }

        } else {

            if (type == 1) {
                try {
                    //提示
                    AppSetup setup = appSetupService.get();
                    if (setup.getOpenRecharge() == 0) {
                        return this.errorJSON(setup.getRechargeTip());
                    }
                    //获取用户信息
                    AppUser user = appUserService.get(getUserId());
                    AppCzMoney appCzMoney = appCzMoneyService.get(projectId);
                    PayInfoResult payInfoResult = wechatPayConfigsService.wechatDiamondRechargeH5(request, user, appCzMoney, mobileSpec);
                    if (ObjectUtil.isEmpty(payInfoResult)) {
                        return this.errorJSON("充值失败，请您重新充值!");
                    }
                    return this.sucessJSON(payInfoResult);
                } catch (Exception e) {
                    logger.error("微信充值异常:", e);
                    return this.errorJSON("服务器繁忙，请您稍后重试!");
                }
            }
            if (type == 2) {
                try {
                    //提示
                    AppSetup setup = appSetupService.get();
                    if (setup.getOpenBuyVip() == 0) {
                        return this.errorJSON(setup.getBuyVipTip());
                    }
                    //获取用户信息
                    AppUser user = appUserService.get(getUserId());
                    VipPackage vipPackage = vipPackageService.info(projectId);
                    PayInfoResult payInfoResult = wechatPayConfigsService.wechatOpenVipRechargeH5(request, user, vipPackage, mobileSpec);
                    if (ObjectUtil.isEmpty(payInfoResult)) {
                        return this.errorJSON("充值失败，请您重新充值!");
                    }
                    return this.sucessJSON(payInfoResult);
                } catch (Exception e) {
                    logger.error("微信充值异常:", e);
                    return this.errorJSON("服务器繁忙，请您稍后重试!");
                }
            }
            if (type == 3) {
                try {

                    //获取用户信息
                    AppUser user = appUserService.get(getUserId());
                    VipPackage vipPackage = new VipPackage();
                    vipPackage.setId(1000);
                    vipPackage.setPrice(new BigDecimal("28.00"));
//                    vipPackage.setPrice(new BigDecimal("0.01"));

                    PayInfoResult payInfoResult = wechatPayConfigsService.wechatOpenVipRechargeH5(request, user, vipPackage, mobileSpec);
                    if (ObjectUtil.isEmpty(payInfoResult)) {
                        return this.errorJSON("充值失败，请您重新充值!");
                    }
                    return this.sucessJSON(payInfoResult);
                } catch (Exception e) {
                    logger.error("支付宝充值异常:", e);
                    return this.errorJSON("服务器繁忙，请您稍后重试!");
                }
            }

            //php门票
            if (type == 4) {
                try {
                    //组装用户信息
                    AppUser user = new AppUser();
                    user.setId(userId);//用户id
                    user.setNick("之约");
                    user.setLoginname(userId.toString());
                    //组装门票价格
                    VipPackage vipPackage = new VipPackage();
                    vipPackage.setId(projectId);
                    vipPackage.setPrice(price);

                    PayInfoResult payInfoResult = wechatPayConfigsService.wechatOpenVipRechargeH5(request, user, vipPackage, mobileSpec);

                    if (ObjectUtil.isEmpty(payInfoResult)) {
                        return this.errorJSON("充值失败，请您重新充值!");
                    }
                    return this.sucessJSON(payInfoResult);
                } catch (Exception e) {
                    logger.error("支付宝充值异常:", e);
                    return this.errorJSON("服务器繁忙，请您稍后重试!");
                }

            }
            if (type == 5) {

                try {
                    //组装用户信息
                    AppUser user = new AppUser();
                    user.setId(userId);//用户id
                    user.setNick("之约");
                    user.setLoginname(userId.toString());

                    //组装vip价格
                    VipPackage vipPackage = new VipPackage();
                    vipPackage.setId(projectId);  //
                    vipPackage.setPrice(price);

                    PayInfoResult payInfoResult = wechatPayConfigsService.wechatOpenVipRechargeH5(request, user, vipPackage, mobileSpec);

                    if (ObjectUtil.isEmpty(payInfoResult)) {
                        return this.errorJSON("充值失败，请您重新充值!");
                    }
                    return this.sucessJSON(payInfoResult);
                } catch (Exception e) {
                    logger.error("支付宝充值异常:", e);
                    return this.errorJSON("服务器繁忙，请您稍后重试!");
                }

            }


        }


        return this.errorJSON("请求参数不正确!");

    }


    /**
     * 微信钻石支付回调
     */
    @RequestMapping(value = "/diamond/wxNotify/{appIdStr}", method = RequestMethod.POST)
    @ResponseBody
    public void diamondH5PayNotifyUrl(HttpServletRequest request, @PathVariable("appIdStr") String appIdStr) throws Exception {
        //获取对应详细信息
        WechatPayConfigs wechatPayConfigs = wechatPayConfigsService.getAppIdInfo(appIdStr);
        //获取报文
        String body = getRequestBody(request);
        //证书序列号
        String serialNumber = request.getHeader("Wechatpay-Serial");
        //随机串
        String Nonce = request.getHeader("Wechatpay-Nonce");
        //时间戳
        String timestamp = request.getHeader("Wechatpay-Timestamp");
        //微信传递过来的签名
        String signature = request.getHeader("Wechatpay-Signature");

        //报文转map
        System.out.println("请求体=" + body);
        Map requestMap = (Map) JSON.parse(body);

        //获取resource
        String resource = String.valueOf(requestMap.get("resource"));
        System.out.println("resource=" + resource);
        Map requestMap2 = (Map) JSON.parse(resource);

        //获取associated_data   nonce   ciphertext
        String associated_data = (String) requestMap2.get("associated_data");
        String nonce = (String) requestMap2.get("nonce");
        String ciphertext = (String) requestMap2.get("ciphertext");

        //按照文档要求拼接验签串
        String VerifySignature = timestamp + "\n" + Nonce + "\n" + body + "\n";
        System.out.println("拼接后的验签串=" + VerifySignature);

        //使用官方验签工具进行验签
        Verifier verifier = verifier(wechatPayConfigs);
        boolean verify = verifier.verify(serialNumber, VerifySignature.getBytes(), signature);
        System.out.println("官方工具验签=" + verify);

        //验证成功执行数据操作
        if (verify) {
            System.out.println("验签成功后，开始进行解密");
            //解密，如果这里报错，就一定是APIv3密钥错误
            AesUtil aesUtil = new AesUtil(wechatPayConfigs.getApiKey().getBytes());
            String aes = aesUtil.decryptToString(associated_data.getBytes(), nonce.getBytes(), ciphertext);
            System.out.println("解密数据：" + aes);
            //判断
            Map map = (Map) JSON.parse(aes);
            String trade_state = (String) map.get("trade_state");
            String orderNum = (String) map.get("out_trade_no");
            if ("SUCCESS".equals(trade_state)) {

                AppOrder topup = appOrderService.getByOrdernum(orderNum, Constants.dingdan_zhiFuLeiXing_wx, dingdan_status_dfk);

                //判断预订单是否存在
                if (!StringUtils.isEmpty(topup)) {
                    //
                    AppUser user = appUserService.get(topup.getUserid());
                    //存在则更改预订单支付状态
                    appOrderService.updateStastusYzf(orderNum, Constants.dingdan_zhiFuLeiXing_wx);
                    //
                    BigDecimal getDiamond = topup.getNum();
                    //添加用户钻石金额
                    appUserService.updateZuanShi(user.getId(), getDiamond);
                    //增加用户累积充值金额
                    appUserService.updateLeijiChongzhi(user.getId(), topup.getMoney());
                    //添加钻石明细
                    appMingXiZuanShiService.addMingxi(user.getId(), getDiamond, 1, "充值");
                    //添加充值明细
                    appMingxiChongzhiService.addMingxi(user.getId(), getDiamond, 1, topup.getMoney(), orderNum, topup.getMobileSpec());
                    //完成充值任务
                    appDailyTasController.getAwardOnce(topup.getUserid(), ClientConstants.TaskOnce.RECHARGE_FIRST);
                    //如果有上级发放用户充值提成
                    addAward(topup);
                    //
                    agentUserService.shareMoneyRecharge(user.getId(), topup.getNum());
                    //升级贵族
                    appPrivilegeService.isUpLevel(user);
                }
            }
        }


    }


    /**
     * 邀请用户充值增加父级提成
     *
     * @param order
     */
    public void addAward(AppOrder order) {
        AppInvitationRecord record = appInvitationRecordService.getShangji(order.getUserid());
        if (record != null) {
            AppSetup appSetup = appSetupService.get();
            BigDecimal divide = order.getNum().multiply(appSetup.getRechargeInvite()).setScale(2, BigDecimal.ROUND_HALF_UP);
            appUserService.addDiamonds(record.getPuserid(), divide, "邀请用户充值提成");
        }
    }


    /**
     * 微信钻石支付回调
     */
    @RequestMapping(value = "/vip/wxNotify/{appIdStr}", method = RequestMethod.POST)
    @ResponseBody
    public void vipH5PayNotifyUrl(HttpServletRequest request, @PathVariable("appIdStr") String appIdStr) throws Exception {

        //获取对应详细信息
        WechatPayConfigs wechatPayConfigs = wechatPayConfigsService.getAppIdInfo(appIdStr);
        //获取报文
        String body = getRequestBody(request);
        //证书序列号
        String serialNumber = request.getHeader("Wechatpay-Serial");
        //随机串
        String Nonce = request.getHeader("Wechatpay-Nonce");
        //时间戳
        String timestamp = request.getHeader("Wechatpay-Timestamp");
        //微信传递过来的签名
        String signature = request.getHeader("Wechatpay-Signature");

        //报文转map
        System.out.println("请求体=" + body);
        Map requestMap = (Map) JSON.parse(body);

        //获取resource
        String resource = String.valueOf(requestMap.get("resource"));
        System.out.println("resource=" + resource);
        Map requestMap2 = (Map) JSON.parse(resource);

        //获取associated_data   nonce   ciphertext
        String associated_data = (String) requestMap2.get("associated_data");
        String nonce = (String) requestMap2.get("nonce");
        String ciphertext = (String) requestMap2.get("ciphertext");

        //按照文档要求拼接验签串
        String VerifySignature = timestamp + "\n" + Nonce + "\n" + body + "\n";
        System.out.println("拼接后的验签串=" + VerifySignature);

        //使用官方验签工具进行验签
        Verifier verifier = verifier(wechatPayConfigs);
        boolean verify = verifier.verify(serialNumber, VerifySignature.getBytes(), signature);
        System.out.println("官方工具验签=" + verify);

        //验证成功执行数据操作
        if (verify) {
            System.out.println("验签成功后，开始进行解密");
            //解密，如果这里报错，就一定是APIv3密钥错误
            AesUtil aesUtil = new AesUtil(wechatPayConfigs.getApiKey().getBytes());
            String aes = aesUtil.decryptToString(associated_data.getBytes(), nonce.getBytes(), ciphertext);
            System.out.println("解密数据：" + aes);
            //判断
            Map map = (Map) JSON.parse(aes);
            String trade_state = (String) map.get("trade_state");
            String orderNum = (String) map.get("out_trade_no");
            if ("SUCCESS".equals(trade_state)) {

                //根据订单号、支付状态、支付方式获取预订单
//                VipOrder vipOrder = vipOrderService.infoByOrderNo(orderNum);
                VipOrder vipOrder = vipOrderService.getByOrderNum(orderNum, dingdan_zhiFuLeiXing_wx, 0);
//                if (ObjectUtil.isNotEmpty(vipOrder) && !vipOrder.getVipPackageId().equals(1000)) {
//                    //更改订单状态
//                    vipOrderService.successCall(orderNum);
//                } else {
//                    VipOrder vipOrder1 = vipOrderService.infoByOrderNo(orderNum);
//                    vipOrder1.setStatus(1);
//                    vipOrderDao.update(vipOrder1);
//                    //更改状态
//                    appUserService.upstateWindowTicket(vipOrder.getUserId());
//                }

                if (ObjectUtil.isNotEmpty(vipOrder)) {
                    Integer vipPackageId = vipOrder.getVipPackageId();
                    //门票
                    if (vipPackageId.equals(1000)) {

                        VipOrder vipOrder1 = vipOrderService.infoByOrderNo(orderNum);
                        vipOrder1.setStatus(1);
                        vipOrderDao.update(vipOrder1);
                        //更改状态
                        appUserService.upstateWindowTicket(vipOrder.getUserId());
                        afterUserService.upWhiteStatus(vipOrder.getUserId(), 2);
                    }
                    //会员
                    if (vipPackageId.equals(101) || vipPackageId.equals(102) || vipPackageId.equals(103)) {

                        //更改订单状态
                        vipOrderService.successCall(orderNum);
                        afterUserService.upWhiteStatus(vipOrder.getUserId(), 2);
                    }
                    //php

                    //4 门票
                    if (vipPackageId.equals(4)) {

                        VipOrder vipOrder1 = vipOrderService.infoByOrderNo(orderNum);
                        vipOrder1.setStatus(1);
                        vipOrderDao.update(vipOrder1);
                        //生成门票数据
                        phpUserService.callBackWindowTick(vipOrder1.getUserId());

                        //可以单独传入http参数，这样参数会自动做URL编码，拼接在URL中

                        Integer types = 1;

                        String param = "key:26e97719fb48687d42681b0ead73c418,uid:" + vipOrder1.getUserId() + ",money:" + vipOrder1.getPrice() + ",type:" + types;

                        String ss = Md5Util1.md5Hex(param);

                        HashMap<String, Object> paramMap = new HashMap<>();

                        paramMap.put("singer", ss);
                        paramMap.put("uid", vipOrder1.getUserId());
                        paramMap.put("money", vipOrder1.getPrice());
                        paramMap.put("type", types);
                        String result = HttpUtil.get("https://poposeapi.ptszyxx.com/apa/Shujuhaonv/play", paramMap);

                        System.out.println(result);

                    }
                    //会员  1三天  2一个月  3六个月  7 12个月
                    if (vipPackageId.equals(1) || vipPackageId.equals(2) || vipPackageId.equals(3) || vipPackageId.equals(7)) {

                        VipOrder vipOrder1 = vipOrderService.infoByOrderNo(orderNum);
                        vipOrder1.setStatus(1);
                        vipOrderDao.update(vipOrder1);
                        //生成会员数据
                        phpUserService.callBackVip(vipOrder1.getUserId(), vipPackageId);

                        Integer types = null;

                        if (vipPackageId.equals(1)) {
                            types = 2;
                        }
                        if (vipPackageId.equals(2)) {
                            types = 3;
                        }
                        if (vipPackageId.equals(3)) {
                            types = 4;
                        }
                        if (vipPackageId.equals(7)) {
                            types = 5;
                        }
                        String param = "key:26e97719fb48687d42681b0ead73c418,uid:" + vipOrder1.getUserId() + ",money:" + vipOrder1.getPrice() + ",type:" + types;

                        String ss = Md5Util1.md5Hex(param);

                        HashMap<String, Object> paramMap = new HashMap<>();

                        paramMap.put("singer", ss);
                        paramMap.put("uid", vipOrder1.getUserId());
                        paramMap.put("money", vipOrder1.getPrice());
                        paramMap.put("type", types);
                        String result = HttpUtil.get("https://poposeapi.ptszyxx.com/apa/Shujuhaonv/play", paramMap);

                        System.out.println(result);

                    }
                }


            }
        }

    }


    public Verifier verifier(WechatPayConfigs wechatPayConfigs) throws Exception {
        //获取证书管理器实例
        CertificatesManager certificatesManager = CertificatesManager.getInstance();
        // 向证书管理器增加需要自动更新平台证书的商户信息
        certificatesManager.putMerchant(wechatPayConfigs.getMchId(), new WechatPay2Credentials(wechatPayConfigs.getMchId(),
                        new PrivateKeySigner(wechatPayConfigs.getMchSerialNo(), PemUtil.loadPrivateKey(wechatPayConfigs.getPrivateKey())))
                , wechatPayConfigs.getApiKey().getBytes(StandardCharsets.UTF_8));
        Verifier verifier = certificatesManager.getVerifier(wechatPayConfigs.getMchId());
        return verifier;
    }


    /**
     * 读取请求数据流
     *
     * @param request
     * @return
     */
    private String getRequestBody(HttpServletRequest request) {

        StringBuffer sb = new StringBuffer();

        try (ServletInputStream inputStream = request.getInputStream();
             BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        ) {
            String line;

            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }

        } catch (IOException e) {
            logger.error("读取数据流异常:{}", e);
        }
        return sb.toString();
    }


}
